package com.ifdom.thread.threethreadprintingABC;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/9/21 11:27
 * @Version 1.0.0
 * @Description
 **/
public class IndexRunnable  implements Runnable {
    private final String threadName;
    private final Object prev;
    private final Object current;

    IndexRunnable(String threadName,Object current, Object prev) {
        this.threadName = threadName;
        this.prev = prev;
        this.current = current;
    }

    @Override
    public void run() {
        System.out.println("threadName: " + this.threadName);
        int count = 10;
        while (count > 0) {
            synchronized (prev) {
                synchronized (current) {
                    System.out.print(threadName + " == ");
                    count--;

                    current.notify();
                }
                try {
                    prev.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}